﻿let pi = 3.141593;
let g = 9.807;
////滚珠公式1
window.addEventListener("load", function () {
    btn.disabled = true;
})
let btn = document.querySelector("#gunzhu1").querySelector("button");
let ipt = document.querySelector("#gunzhu1").querySelectorAll("input");
////将按钮设置为禁用，达到条件后启用
window.addEventListener('input', function () {
    if (!(ipt[0].value == "" || ipt[1].value == "" || ipt[2].value == "" || ipt[3].value == "" || ipt[4].value == "" || ipt[5].value == "")) {
        btn.disabled = false;
    }
    else {
        btn.disabled = true;
    }
})
btn.addEventListener("click", function () {

    let a = parseFloat(ipt[0].value) * parseFloat(ipt[1].value) / (2 * pi* parseFloat(ipt[2].value))
    let b =parseFloat(ipt[3].value) * parseFloat(ipt[4].value) * parseFloat(ipt[1].value) / (2 * pi)
    let jieGuo = (a+b) * (1 / parseFloat(ipt[5].value))
    ipt[6].value = jieGuo.toFixed(4);
})
/////滚珠公式2
window.addEventListener("load", function () {
    gunzhu2Btn.disabled = true;
})
let gunzhu2Btn = document.querySelector("#gunzhu2").querySelector("button");
let gunzhu2Ipt = document.querySelector("#gunzhu2").querySelectorAll("input");
window.addEventListener('input', function () {
    if (!(gunzhu2Ipt[0].value == "" || gunzhu2Ipt[1].value == "" || gunzhu2Ipt[2].value == "" || gunzhu2Ipt[3].value == "")) {
        gunzhu2Btn.disabled = false;
    }
    else {
        gunzhu2Btn.disabled = true;
    }
})
gunzhu2Btn.addEventListener("click", function () {
    let sinα = Math.sin(parseFloat(gunzhu2Ipt[2].value) * pi / 180); 
    let cosα = Math.cos(parseFloat(gunzhu2Ipt[2].value) * pi / 180);
    let jieGuo2 = parseFloat(gunzhu2Ipt[0].value) + parseFloat(gunzhu2Ipt[1].value) * g * (sinα + parseFloat(gunzhu2Ipt[3].value) * cosα);
    gunzhu2Ipt[4].value = jieGuo2.toFixed(4);
})
/////滑轮驱动下负载转矩
let hualunBtn = document.querySelector("#hualun").querySelector("button");
let hualunIpt = document.querySelector("#hualun").querySelectorAll("input");
window.addEventListener("load", function () {
    hualunBtn.disabled = true;
})
window.addEventListener('input', function () {
    if (!(hualunIpt[0].value == "" || hualunIpt[1].value == "" || hualunIpt[2].value == "" || hualunIpt[3].value == "")) {
        hualunBtn.disabled = false;
    }
    else {
        hualunBtn.disabled = true;
    }
})
hualunBtn.addEventListener("click", function () {
    let a = 0.05 * parseFloat(hualunIpt[0].value) + (parseFloat(hualunIpt[1].value) * g)
    let jieGuo2 = (a* parseFloat(hualunIpt[2].value)) / (2 * parseFloat(hualunIpt[3].value))
    hualunIpt[4].value = jieGuo2.toFixed(4);
})
////金属线、皮带负载转矩
let jinshuBtn = document.querySelector("#jinshu").querySelector("button");
let jinshuIpt = document.querySelector("#jinshu").querySelectorAll("input");
window.addEventListener("load", function () {
    jinshuBtn.disabled = true;
})
window.addEventListener('input', function () {
    if (!(jinshuIpt[0].value == "" || jinshuIpt[1].value == "" || jinshuIpt[2].value == "" || jinshuIpt[3].value == "")) {
        jinshuBtn.disabled = false;
    }
    else {
        jinshuBtn.disabled = true;
    }
})
jinshuBtn.addEventListener("click", function () {
    let a = parseFloat(jinshuIpt[0].value) * parseFloat(jinshuIpt[1].value)
    let jieGuo =  a / (2 * parseFloat(jinshuIpt[2].value) * parseFloat(jinshuIpt[3].value))
    jinshuIpt[4].value = jieGuo.toFixed(4);
})
/////齿轮、齿条下负载转矩
let chilunBtn = document.querySelector("#chilun").querySelector("button");
let chilunIpt = document.querySelector("#chilun").querySelectorAll("input");
window.addEventListener("load", function () {
    chilunBtn.disabled = true;
})
window.addEventListener('input', function () {
    if (!(chilunIpt[0].value == "" || chilunIpt[1].value == "" || chilunIpt[2].value == "" || chilunIpt[3].value == "")) {
        chilunBtn.disabled = false;
    }
    else {
        chilunBtn.disabled = true;
    }
})
chilunBtn.addEventListener("click", function () {
    let sinα = Math.sin(parseFloat(chilunIpt[2].value) * pi / 180);
    let cosα = Math.cos(parseFloat(chilunIpt[2].value) * pi / 180);
    let jieGuo2 = parseFloat(chilunIpt[0].value) + parseFloat(chilunIpt[1].value) * g * (sinα + parseFloat(chilunIpt[3].value) * cosα);
    chilunIpt[4].value = jieGuo2.toFixed(4);
})
///////实际测试计算方法
let shijiBtn = document.querySelector("#shiji").querySelector("button");
let shijiIpt = document.querySelector("#shiji").querySelectorAll("input");
window.addEventListener("load", function () {
    shijiBtn.disabled = true;
})
window.addEventListener('input', function () {
    if (!(shijiIpt[0].value == "" || shijiIpt[1].value == "")) {
        shijiBtn.disabled = false;
    }
    else {
        shijiBtn.disabled = true;
    }
})
shijiBtn.addEventListener("click", function () {
    let jieGuo2 = (parseFloat(shijiIpt[0].value) * parseFloat(shijiIpt[1].value))/2
    shijiIpt[2].value = jieGuo2.toFixed(4);
})
